package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.PageResponseResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.model.wemedia.pojos.WmNewsMaterial;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.models.auth.In;
import org.simpleframework.xml.Path;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Resource
    private WmMaterialService wmMaterialService;
    @PostMapping("/upload_picture")
    public ResponseResult<WmMaterial> upload(@RequestParam("multipartFile") MultipartFile multipartFile){
        WmMaterial wmMaterial = wmMaterialService.upload(multipartFile);
        return ResponseResult.okResult(wmMaterial);
    }

    @PostMapping("/list")
    public PageResponseResult<List<WmMaterial>> selectByPage(@RequestBody WmMaterialDto wmMaterialDto){
        return wmMaterialService.selectByPage(wmMaterialDto);
    }

    /**
     *  删除图片
     * @param id 图片id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult<Object> delImage(@PathVariable("id") Integer id){
        return wmMaterialService.delImage(id);
    }

    /**
     *  取消收藏图片
     * @param id 图片id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult<Object> concelCollect(@PathVariable("id") Integer id){
        return wmMaterialService.concelCollect(id);
    }
    /**
     *  收藏图片
     * @param id 图片id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult<Object> collect(@PathVariable("id") Integer id){
        return wmMaterialService.collect(id);
    }
}
